<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="utils.js"></script>
<script src="session-storage-utils.js"></script>
<script>
RunSessionStorageTest(async (isPrerendering, url, prerenderChannel, done) => {
  if (!isPrerendering) {
    startPrerendering(url);

    // Wait for the message from the prerendering page.
    assert_equals(
        await getNextMessage(prerenderChannel),
        'From prerendering page')

    assert_equals(
        getSessionStorageKeys(),
        '',
        'The session storage item set by the prerendering page must not be ' +
        'visible in the initiator page.');

    done();
  } else {
    sessionStorage.setItem('set by prerendering page', '1');

    assert_equals(
        getSessionStorageKeys(),
        'set by prerendering page',
        'The session storage item must have been added by the prerendering' +
        ' page.');
    // Send the message to the initiator page.
    prerenderChannel.postMessage('From prerendering page');
  }
});
</script>
